<?php
class KolSys_RegExp_Methods
{
	private $regExpStr='';
	private $start;
	private $end;
	public function getMatchOffset()
	{
		return array($this->start,$this->end);
	}
	public function __construct($regExpStr)
	{
		$this->regExpStr=$regExpStr;
	}
	public function match($str)
	{
		if(preg_match($this->regExpStr, $str, $matches,PREG_OFFSET_CAPTURE))
		{
			list($fullMatch,$offset)=$matches[0];
			$this->start=$offset;
			$this->end=$offset+strlen($fullMatch);
			$out=array();
			foreach($matches as $m)
			{
				$out[]=$m[0];
			}
			return $out;
		}else{
			return false;
		}
	}
	public function matchAll($str,$flags=PREG_PATTERN_ORDER)
	{
		if(preg_match_all($this->regExpStr, $str, $matches,$flags))
		{
			return $matches;
		}else{
			return false;
		}
	}
	public function replace($replacement,$str)
	{
		return preg_replace($this->regExpStr, $replacement, $str);
	}
}